﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CuaHangBangDia.NV
{
    class SapXepLV : System.Collections.IComparer
    {
        #region - field(s) -

        private int mSortingColumnIndex;

        private System.Windows.Forms.SortOrder mSortOrderEnumerator;

        private System.Collections.CaseInsensitiveComparer mObjectComparer;

        #endregion

        #region - constructor(s) -

        public SapXepLV()
        {
            mSortingColumnIndex = 0;

            mSortOrderEnumerator = System.Windows.Forms.SortOrder.None;

            mObjectComparer = new System.Collections.CaseInsensitiveComparer();
        }

        #endregion

        #region - method(s) -

        #region - inherited from IComparer interface -

        int System.Collections.IComparer.Compare(object x, object y)
        {
            int result;

            System.Windows.Forms.ListViewItem itemOne, itemTwo;

            // casts the objects to be compared to ListViewItem objects.
            itemOne = (System.Windows.Forms.ListViewItem)x;
            itemTwo = (System.Windows.Forms.ListViewItem)y;

            // compares two items...
            result = mObjectComparer.Compare(itemOne.SubItems[mSortingColumnIndex].Text, itemTwo.SubItems[mSortingColumnIndex].Text);

            // calculate correct return value based on object comparison...
            if (mSortOrderEnumerator == System.Windows.Forms.SortOrder.Ascending) return result;

            else if (mSortOrderEnumerator == System.Windows.Forms.SortOrder.Descending) return (-result);

            else // equal...
                return 0;
        }

        #endregion

        #endregion

        #region - property(ies) -

        public int SortingColumnIndex
        {
            get { return mSortingColumnIndex; }

            set { mSortingColumnIndex = value; }
        }

        public System.Windows.Forms.SortOrder SortingOrder
        {
            get { return mSortOrderEnumerator; }

            set { mSortOrderEnumerator = value; }
        }

        #endregion

    }
}
